<%@ page isELIgnored="false" %><%--isELIgnored=true禁用EL表达式--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- JSTL标签库是一个JSP标签的集合，封装了许多jsp应用程序通用的核心功能-->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css"/>
    <script src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
    <style>
        .layui-row{
            margin-bottom: 30px;
        }
        #d1{
            margin-left: 20px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div id="d1">
    <button class="layui-btn" type="button" onclick="add()">添加</button>
    <!-- <table class="layui-table" lay-even lay-skin="nob">
            无边框表格（内部结构参见右侧目录“常规用法”）
        </table> -->
    <table class="layui-table">
        <!-- colgroup中可以使用col来定义表格单元格宽度， -->
        <colgroup>
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>序号</th>
            <th>ID</th>
            <th>名称</th>
            <th>密码</th>
            <th>权限</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="manager">
            <tr>
                <td>${manager.id}</td>
                <td>${manager.id}</td>
                <td>${manager.mName}</td>
                <td>${manager.mPass}</td>
                <td>
                    <c:if test="${manager.mLevel == 1}">超级管理员</c:if>
                    <c:if test="${manager.mLevel == 0}">管理员</c:if>
                </td>
                <td>
                    <c:if test="${manager.mLevel == 0}">
                     <c:if test="${manager.mStatus == 1}">正常</c:if>
                    </c:if>
                     <c:if test="${manager.mStatus == 0}">禁用</c:if>
                </td>
                <td>
                    <c:if test="${manager.mLevel == 0}">
                        <c:if test="${manager.mStatus == 1}">
                            <button style="color: red" type="button" class="layui-btn" onclick="update('${manager.id}','${manager.mStatus}')">禁用</button>
                        </c:if>
                    </c:if>
                    <c:if test="${manager.mStatus == 0}">
                        <button type="button" class="layui-btn" onclick="update('${manager.id}','${manager.mStatus}')">启用</button>
                    </c:if>
                </td>
            </tr>
        </c:forEach>

        </tbody>
    </table>
    <div id="test1" style="text-align: center;"></div>
    <div style="text-align: center;">
        <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="queryByPageNO(1,${totalPage})">首页</button>
        <button class="layui-btn" onclick = "queryByPageNO(${pageNo-1},${totalPage})">上一页</button>
        <span class = "layui-font-16">${pageNo} / ${totalPage}页</span>
        <button class="layui-btn" onclick = "queryByPageNO(${pageNo+1},${totalPage})">下一页</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="queryByPageNO(${totalPage},${totalPage})">尾页</button>
    </div>
</div>
</body>
<script type="text/javascript">
    function queryByPageNO(pageNo,totalPage){
        if(pageNo <= totalPage){
            //查询条件
            // var params = $("form").serialize();
            if(pageNo < 1) pageNo = 1;
            window.location.href = "http://localhost:8080/shopping/manager/queryAllAdmin?&pageNo="+pageNo;
            // window.location.href = "http://localhost:8080/shopping/manager/queryAllAdmin?"+params+"&pageNo="+pageNo;
        }
    }
    layui.use('layer', function(){
        var layer = layui.layer;
    });
    function add(){
        layer.open({
            type: 2,
            area: ['480px', '300px'],
            title: "添加管理员页面",
            content: 'http://localhost:8080/shopping/manager/addManagerPage',
            yes: function(index, layero) {
                layer.close(index);
            },
        })
    }
    function update(id,mStatus){
        // var params = $("form").serialize();
        // console.info(params);
        console.info(id)
        $.ajax({
            url: "http://localhost:8080/shopping/manager/updateOneManager",
            data: "id="+id+"&mStatus="+mStatus,
            type: "post",
            success: function(code){
                if(code == '1'){
                    alert("修改成功");
                } else {
                    alert("修改失败");
                }
                //延迟关闭
                setTimeout(closeLayer(), 500);
            }
        });
    }
    function closeLayer(){
        // //关闭弹出层
        // var index = parent.layer.getFrameIndex(window.name);
        // parent.layer.close(index);
        //刷新父页面
        window.parent.location.reload();
    }
</script>
</head>
</html>